﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HM
{
    [HotUpdate]
    [Description("付款单保存后回写平台对账单")]
    public class FKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            string FID = "", FDZENtryId="",FBillNo="";
            foreach (DynamicObject item in e.DataEntitys)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo= Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AP_PAYBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for(int i=0; i<DynamData.Count;i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='已下推付款单',F_RXWU_Text7='{1}' where FENTRYID='{0}'", FDZENtryId, FBillNo);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }
    [HotUpdate]
    [Description("付款单删除后回写平台对账单")]
    public class DeleteFKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
        {
            base.BeforeExecuteOperationTransaction(e);
            string FID = "", FDZENtryId = "", FBillNo = "";
            foreach (ExtendedDataEntity item in e.SelectedRows)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo = Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AP_PAYBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for (int i = 0; i < DynamData.Count; i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='',F_RXWU_Text7='' where FENTRYID='{0}'", FDZENtryId);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }

    [HotUpdate]
    [Description("付款退款单保存后回写平台对账单")]
    public class FKTKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            string FID = "", FDZENtryId = "", FBillNo="";
            foreach (DynamicObject item in e.DataEntitys)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo = Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AP_REFUNDBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for (int i = 0; i < DynamData.Count; i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='已下推付款退款单',F_RXWU_Text7='{1}' where FENTRYID='{0}'", FDZENtryId, FBillNo);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }
    [HotUpdate]
    [Description("付款退款单删除后回写平台对账单")]
    public class DeleteFKTKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
        {
            base.BeforeExecuteOperationTransaction(e);
            string FID = "", FDZENtryId = "", FBillNo = "";
            foreach (ExtendedDataEntity item in e.SelectedRows)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo = Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AP_REFUNDBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for (int i = 0; i < DynamData.Count; i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='',F_RXWU_Text7='' where FENTRYID='{0}'", FDZENtryId);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }
    [HotUpdate]
    [Description("收款单保存后回写平台对账单")]
    public class SKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            string FID = "", FDZENtryId = "", FBillNo="";
            foreach (DynamicObject item in e.DataEntitys)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo = Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AR_RECEIVEBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for (int i = 0; i < DynamData.Count; i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='已下推收款单',F_RXWU_Text7='{1}' where FENTRYID='{0}'", FDZENtryId, FBillNo);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }
    [HotUpdate]
    [Description("收款单删除后回写平台对账单")]
    public class DeleteSKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
        {
            base.BeforeExecuteOperationTransaction(e);
            string FID = "", FDZENtryId = "", FBillNo = "";
            foreach (ExtendedDataEntity item in e.SelectedRows)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo = Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AR_RECEIVEBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for (int i = 0; i < DynamData.Count; i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='',F_RXWU_Text7='' where FENTRYID='{0}'", FDZENtryId);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }
    [HotUpdate]
    [Description("收款退款单保存后回写平台对账单")]
    public class SKTKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);
            string FID = "", FDZENtryId = "", FBillNo="";
            foreach (DynamicObject item in e.DataEntitys)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo = Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AR_REFUNDBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for (int i = 0; i < DynamData.Count; i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='已下推收款退款单',F_RXWU_Text7='{1}' where FENTRYID='{0}'", FDZENtryId, FBillNo);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }
    [HotUpdate]
    [Description("收款退款单删除后回写平台对账单")]
    public class DeleteSKTKBackToPTDZ : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
        {
            base.BeforeExecuteOperationTransaction(e);
            string FID = "", FDZENtryId = "", FBillNo = "";
            foreach (ExtendedDataEntity item in e.SelectedRows)
            {
                FID = Convert.ToString(item["ID"]);
                FBillNo = Convert.ToString(item["BillNo"]);
                string SQL = "/*dialect*/" + string.Format(@" SELECT FDZENtryId FROM T_AR_REFUNDBILLENTRY where FDZENtryId<>'' AND FID='{0}'", FID);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    for (int i = 0; i < DynamData.Count; i++)
                    {
                        FDZENtryId = Convert.ToString(DynamData[i]["FDZENtryId"]);
                        string SQL0 = "/*dialect*/" + string.Format(@"UPDATE RXWU_t_Cust_Entry100014 set F_RXWU_Text6='',F_RXWU_Text7='' where FENTRYID='{0}'", FDZENtryId);
                        DBUtils.ExecuteDynamicObject(this.Context, SQL0);
                    }
                }
            }
        }
    }
}